//###############
//FILE : FileManagerInfo.java
//WRITER : Daniel Lowengrub, daniel_i_l, 320687098
//EXERCISE : oop ex3 2011
//DESCRIPTION:
//See below
//###############

package oop.ex3.nameserver;

import java.util.ArrayList;
import java.util.LinkedHashSet;

/**
 * This class holds information about a specific FM. It mainly provides methods for
 * checking and changing the list of files that the FM holds.
 * @author daniel
 */
public class FileManagerInfo {
    private LinkedHashSet<String> _fileNames;

    /**
     * Construct a new file manger information instance.
     */
    public FileManagerInfo() {
        _fileNames = new LinkedHashSet<String>();
    }

    /**
     * Create a new file manager info instance and initialize it with a list of file names.
     * @param fileNames The list of file name to initialize the FM info with.
     */
    public FileManagerInfo(ArrayList<String> fileNames) {
        _fileNames = new LinkedHashSet<String>();
        for (String fileName : fileNames)
            _fileNames.add(fileName);
    }

    /**
     * Add a file to the list.
     * @param fileName The file to add.
     */
    public void addFile(String fileName) {
        _fileNames.add(fileName);
    }

    /**
     * Remove a file from the list.
     * @param fileName The file to remove.
     */
    public void removeFile(String fileName) {
        _fileNames.remove(fileName);
    }

    /**
     * Check if the FM has a specific file.
     * @param fileName The file to look for.
     * @return True iff the file exists.
     */
    public boolean hasFile(String fileName) {
        return _fileNames.contains(fileName);
    }
    
    /**
     * Return a list of all the current file names.
     * @return The list of file names.
     */
    public ArrayList<String> getFileNames() {
        ArrayList<String> fileNames = new ArrayList<String>();
        for (String fileName : _fileNames)
            fileNames.add(fileName);
        
        return fileNames;
    }

}
